home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
system
/
idt.zip
/
IDT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-06-12
|
31KB
|
1,338 lines
#pragma title("IDT - Find Internal Data Table")
#pragma subtitle("Introduction")
/*
** program: idt
**
** purpose: This program finds the internal device
** table used by MS-DOS and reports its
** contents. It includes options to dump
** and/or display each of the various
** structures pointed to by the idt.
**
** usage: idt
**
** switches: -i = List the internal data table
** -p = List the physical device table
** -l = List the logical device table
** -d = List the device driver headers
** -m = List the memory arena
** -b = List buffer control blocks
** -f = List internal file control blocks
** -c = List file control blocks
** -v = Verbose (dump buffers)
** -* = Everything (except verbose)
**
** notes: Much (most) of the information contained in
** the idt (including the method used to find
** it) is undocumented and subject to change
** and/or errors. This version will not work
** for versions of MS-DOS previous to 3.0.
**
** Considering the wealth of information revealed
** in these tables, it may me a reasonable risk
** for an application which takes some care to
** utilize it - even though it is officially
** undocumented and will not be supported by
** the OS vendor (yes, you know who you are!)
**
** author: Bill Parrott
**
** Copyright (c) 1988, Bill Parrott
** All Rights Reserved
**
** Use this code in any way and the information
** contained herein any way you like, without
** restriction. If you accomplish something
** because of what you got here, and if it makes
** you rich, well I just hope you'll remember
** who made it all possible :-). Seriously, a
** little credit would be nice but apart from
** that, have at it!
*/
#define VERSION 1
#define REVISION 0
#define PROGRAMNAME "IDT"
/*
** system includes
*/
#include <stdio.h>
#include <dos.h>
#include <ctype.h>
#include <assert.h>
#include <process.h>
/*
** site includes
*/
#include <local/getargs.h>
#include <local/what.h>
#include "idt.h"
#pragma subtitle("Data and Definitions")
#pragma page()
/*
** global data
*/
IDT *idt; /* address of internal data table */
/*
** this cell is filled by our function rather that
** from the idt just so we can say we really did it.
*/
segment arenastart; /* start of memory arena */
/*
** switch data
*/
static int doidt = 0; /* list the internal data table */
static int dopdpt = 0; /* list the physical device table */
static int doldt = 0; /* list the logical device table */
static int dodevhdr = 0; /* list device driver headers */
static int doarena = 0; /* list memory arena */
static int dobcb = 0; /* list buffer control blocks */
static int verbose = 0; /* verbose listing (dumps buffers) */
static int doifcb = 0; /* list internal file control blocks */
static int dofcbt = 0; /* list file control blocks */
static int doall = 0; /* list everything */
/*
** switch table
*/
ARG swtab[] =
{
{ 'i', BOOLEAN, &doidt, "List internal data table" },
{ 'p', BOOLEAN, &dopdpt, "List physical device table" },
{ 'l', BOOLEAN, &doldt, "List logical device table" },
{ 'd', BOOLEAN, &dodevhdr, "List device driver headers" },
{ 'm', BOOLEAN, &doarena, "List memory arena" },
{ 'b', BOOLEAN, &dobcb, "List buffer control blocks" },
{ 'f', BOOLEAN, &doifcb, "List internal file control blocks" },
{ 'c', BOOLEAN, &dofcbt, "List file control blocks" },
{ 'v', BOOLEAN, &verbose, "Verbose (dump buffers)" },
{ '*', BOOLEAN, &doall, "List everything" }
};
#define TABSIZE (sizeof(swtab) / sizeof(ARG))
/*
** prototypes
*/
int main( int, char ** );
segment findarena( void );
segment isarena( segment, segment );
void showidt( IDT far * );
void showpdpt( PDPT far * );
void showpdpt1( PDPT far * );
void showldt( LDT far * );
void showdevhdr( DEVHDR far * );
void showdevhdr1( DEVHDR far * );
char *trimname( char far *, int );
void showarena( MDB far * );
int isenv( char far * );
int ispsp( char far * );
void showbcb( BCB far * );
void dumpbuffer( byte far * );
void paragraph( byte *, word );
void memkpy( byte *, byte far *, int );
int memkmp( byte *, byte far *, int );
void showifcb( CHAIN far *, int );
void showifcb1( IFCB far * );
/*
** "what" strings
*/
static char *WhatStrings[] =
{
WHATVER(PROGRAMNAME,VERSION,REVISION),
WHATWHEN,
WHATDATE,
WHAT("Copyright (c) 1988, Bill Parrott"),
WHAT(" All Rights Reserved")
};
#pragma subtitle("main()")
#pragma page()
/*
** main (need I say more?)
*/
int main( argc, argv )
int argc;
char *argv[];
{
union REGS r;
struct SREGS s;
IDT safeplaceforidt;
IDT far *p;
int i;
/*
** signon
*/
fprintf( stderr, "\n%s", &WhatStrings[0][4] );
fprintf( stderr, "\n%s\n", &WhatStrings[3][4] );
/*
** check for version
*/
r.h.ah = 0x30;
intdos( &r, &r );
if ( r.h.al < 0 )
{
fprintf( stderr, "\nIncorrect version of MS-DOS.\n" );
return ( 1 );
}
/*
** process the command line
*/
argc = getargs( argc, argv, swtab, TABSIZE );
if ( doall )
doidt = dopdpt = doldt = dodevhdr =
doarena = dobcb = doifcb = dofcbt = 1;
else
{
i = doidt + dopdpt + doldt + dodevhdr +
doarena + dobcb + doifcb + dofcbt;
if ( i == 0 )
{
fprintf( stderr, "\nusage: idt switch(es)\n" );
fprintf( stderr, "\n\t-i = list the internal data table" );
fprintf( stderr, "\n\t-p = list the physical device table" );
fprintf( stderr, "\n\t-l = list the logical device table" );
fprintf( stderr, "\n\t-d = list the device driver headers" );
fprintf( stderr, "\n\t-m = list the memory arena" );
fprintf( stderr, "\n\t-b = list buffer control blocks" );
fprintf( stderr, "\n\t-f = list internal file control blocks" );
fprintf( stderr, "\n\t-c = list file control blocks" );
fprintf( stderr, "\n\t-v = verbose (dump buffers)" );
fprintf( stderr, "\n\t-* = list all tables" );
fprintf( stderr, "\n" );
return ( 1 );
}
}
/*
** find the memory arena on our own first.
*/
if ( (arenastart = findarena()) == 0 )
{
fprintf( stderr, "\n\n\a+++ Can't locate the first memory descriptor!! +++\n" );
return ( 1 );
}
/*
** now look up the internal data table
*/
segread( &s );
r.h.ah = 0x52; /* magic undocumented function */
intdosx( &r, &r, &s );
/*
** get a static copy for playing with
*/
idt = &safeplaceforidt;
FP_SEG(p) = s.es;
FP_OFF(p) = r.x.bx - 8;
memkpy( (byte *) idt, (byte far *) p, sizeof(IDT) );
/*
** process selections
*/
if ( doidt )
showidt( idt );
if ( dopdpt )
showpdpt( idt->pdpt );
if ( doldt )
showldt( idt->ldt );
if ( dodevhdr )
showdevhdr( &idt->nuldev );
if ( doarena )
showarena( idt->arena );
if ( dobcb )
showbcb( idt->bcbhead );
if ( doifcb )
showifcb( idt->ifcb, 1 );
if ( dofcbt )
showifcb( idt->fcbt, 0 );
/*
** clean up
*/
printf( "\n" );
return ( 0 );
}
#pragma subtitle("findarena() - find start of memory arena")
#pragma page()
/*
** function: findarena
**
** purpose: This function demonstrates a well behaved (?)
** technique for finding the first memory control
** block. It uses only information obtained from
** Microsoft literature and documents in this
** task... (hopefully freeing it from version
** dependancies.) We do, however, make the
** assumption that MS-DOS memory descriptors
** are ALWAYS on paragraph boundaries.
**
** usage: first = findarena();
** segment first;
**
** returns: segment of first descriptor if found,
** else 0.
*/
segment findarena()
{
word beginsearch;
word endsearch;
union REGS r;
/*
** find a place to give up the search. For further
** reliability, we make this the end of physical
** memory (as DOS knows it). Besides, the function
** isarena() requires it.
*/
beginsearch = 0x40; /* after interrupt table */
int86( 0x12, &r,